package com.scujj.cs6.controller;

import com.scujj.cs6.annotation.AuthCheck;
import com.scujj.cs6.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "测试接口", description = "测试接口")
@RestController
@RequestMapping("/test")
public class TestController {
    @Operation(summary = "测试接口", description = "测试接口")
    @GetMapping("/")
    @ApiResponse(
            responseCode = "200",
            description = "成功",
            content = @Content(
                    mediaType = "application/json",
                    examples = @ExampleObject(value = "{\"code\": 200, \"message\": \"成功\", \"data\": \"Hello, World!\"}")
            )
    )
    public Result<String> no_auth() {
        return Result.success("Hello, World!");
    }


    @Operation(summary = "测试认证接口", description = "需要认证的接口")
    @GetMapping("/auth")
    @AuthCheck
    @Parameter(name = "Authorization", description = "认证信息", required = true, in = ParameterIn.HEADER)
    @ApiResponse(
            responseCode = "200",
            description = "成功",
            content = @Content(
                    mediaType = "application/json",
                    examples = @ExampleObject(value = "{\"code\": 200, \"message\": \"成功\", \"data\": \"Hello, World!\"}")
            )
    )
    public Result<String> auth() {
        return Result.success("Hello, World!");
    }
}
